home *** CD-ROM | disk | FTP | other *** search
- Path: news.nstn.ca!news
- From: keichele@ac.dal.ca (Klaus Eichele)
- Newsgroups: comp.lang.c
- Subject: Re: floating point dynamic array
- Date: Tue, 30 Jan 1996 18:29:12 GMT
- Organization: Dalhousie University
- Message-ID: <4ela12$fu3@news.nstn.ca>
- References: <310EFD40.2D03@se.cuhk.hk>
- NNTP-Posting-Host: rewasylishen.chem.dal.ca
- X-Newsreader: Forte Free Agent 1.0.82
-
- Lawrence Xiao <hkshiou3@se.cuhk.hk> wrote:
-
- >Hi all,
-
- >I try to use dynamic array to store series of floating point.
- >But error message returns. However, there won't be any problem
- >when I change the all the declaration from floating point
- >to integer.
-
- >The message I get is:
- >"scanf: floating point formats not linked"
- >"abnormal program termination"
-
- >The program is as follows:
-
- >#include <stdio.h>
- >#include <stdlib.h>
-
- >main()
- >{
- > int n, k;
- > float *base, *ptr;
-
- > scanf("%d", &n);
- > base=calloc(n, sizeof(float));
- > for(ptr=base, k=0;k<n;k++)
- > scanf("%f", ptr++);
- > for(ptr=base+n, k=0;k<n;k++)
- > printf("%f\n", *(--ptr));
- > free(base);
- >}
-
-
- >Can anybody here can drew some light on it?
-
- >Lawrence
-
- Obviously, you are having a Borland compiler. To quote from the
- comp.lang.c FAQ (excellent document, by the way, and worth downloading
- AND reading):
- ===================
- 14.13: Turbo C and "floating point formats not linked."
-
- Some compilers for small machines, including Borland's (and Ritchie's
- original PDP-11 compiler), leave out certain floating point support if
- it looks like it will not be needed. In particular, the
- non-floating-point versions of printf() and scanf() save space by not
- including code to handle %e, %f, and %g. It happens that Borland's
- heuristics for determining whether the program uses floating point are
- insufficient, and the programmer must sometimes insert an extra,
- explicit call to a floating-point library routine to force loading
- of floating-point support. (See the comp.os.msdos.programmer FAQ list
- for more information.)
- ====================
- This problem is well-documented and in the Borland README.TXT, you
- will find the following cure:
- ====================
- Because you can get this error in a number of different ways, check
- the following list of potential causes to find out how to resolve the
- error. The causes are listed in order of most common to least common.
-
- 1. CAUSE: Floating point set to <None>. You have your
- floating point option set to None when it should be set to
- either Fast or Normal.
-
- FIX: Set Floating Point to Fast or Normal.
-
- 2. CAUSE: Either the compiler is over-optimizing, or the
- floating-point formats really do need to be linked in because
- your program manipulates floats in a limited and specific
- fashion. Under certain obscure conditions, the compiler will
- ignore floating point usage in scanf() (e.g., trying to
- read into a float variable that is part of an array contained
- in a structure.)
-
- FIX: Add the following to one source module:
-
- extern _floatconvert;
- #pragma extref _floatconvert
-
- 3. CAUSE: Forgetting to put the address operator & on the scanf
- variable expression. For example,
- float foo;
- scanf("%f", foo);
-
- FIX: Change the code so that the & operator is used where it
- is needed. For example, the above code should be
- float foo;
- scanf("%f", &foo);
-
-
-
- -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
- Klaus Eichele keichele@ac.dal.ca
- http://ac.dal.ca/~keichele/keichele.html
-
-